import unittest

import HTMLTestRunner

from TS_common.TS_regirter import TinyShop_1


class test_get(unittest.TestCase):

    def setUp(self):  #初始化
        print('start..')
        self.m=TinyShop_1()

    def test_case1(self):  #均填写正确
        t= TinyShop_1()
        r = t.regirter("test777777@qq.com","123456","123456")
        self.assertIn("value=\"http://mail." ,r)

    def test_case2(self):   #当邮箱为空时
        t= TinyShop_1()
        r = t.regirter("","123456","123456")
        self.assertIn("error:true,msg:\"邮箱不能为空！\"" ,r)

    def test_case3(self):#当密码和确认密码为空时
        t= TinyShop_1()
        r = t.regirter("test8888885@qq.com","","")
        self.assertIn("error:true,msg:\"密码长度必需大于6位！\"" ,r)

    def test_case4(self): #当密码和确认密码小于六位数时
        t= TinyShop_1()
        r = t.regirter("test8888886@qq.com","123","123")
        self.assertIn("error:true,msg:\"密码长度必需大于6位！\"" ,r)

    def test_case5(self): #当两次密码不一致时
        t= TinyShop_1()
        r = t.regirter("test8888887@qq.com","123456","654321")
        self.assertIn("error:true,msg:\"两次密码输入不一致！\"" ,r)

    def test_case6(self): #当邮箱，密码，确认密码都不输入时
        t= TinyShop_1()
        r = t.regirter("","","")
        self.assertIn("error:true,msg:\"邮箱不能为空！\"" ,r)

    def test_case7(self): #当验证码输入错误时
        t= TinyShop_1()
        r = t.regirter("test999999@qq.com","123456","654321")
        self.assertIn("error:true,msg:\"验证码错误!\"" ,r)
    def tesT_case8(self):  #当输入已注册的邮箱时
        t= TinyShop_1()
        r = t.regirter("test999999@qq.com","123456","123456")
        self.assertIn("error:true,msg:\"此用户已经被注册！\"" ,r)


    def tearDown(self): #资源回收
        print('end..')

if __name__=="__main__":
    su = unittest.TestSuite(unittest.TestLoader().loadTestsFromTestCase(test_get))
    f = open('../TS_TestRunner/report.html','wb')
    r = HTMLTestRunner.HTMLTestRunner(
        stream=f,
        title='TinyShop测试报告',
        description='通过情况')

    r.run(su)
    f.close()